package com.example.navigationbasicdemo.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.navigationbasicdemo.R;

/**
 * @author: njb
 * @date: 2020/9/5 0005 1:23
 * @desc:
 */
public class SecondFragment extends Fragment {
    TextView tvTitle, tvAge;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);
        tvTitle = view.findViewById(R.id.tvTitle);
        tvAge = view.findViewById(R.id.tvSub);
        Bundle bundle = getArguments();
        //普通方式接收参数
        if (bundle != null) {
            String userName = bundle.getString("name");
            int age = bundle.getInt("age");
            Log.d("bundleData1", "姓名:" + userName + "年龄:" + age);
            tvTitle.setText(userName);
            tvAge.setText(String.valueOf(age));
        }
        //通过safe args接收参数
 /*       if (bundle != null) {
            String userName = MainFragmentArgs.fromBundle(bundle).getName();
            int age = MainFragmentArgs.fromBundle(bundle).getAge();
            Log.d("bundleData2", " 姓名: " + userName + " 年龄: " + age);
            tvTitle.setText(userName);
            tvAge.setText(String.valueOf(age));
        }*/
        return view;
    }
}
